package leetcode.weekly.week333;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

//Solution1Test
public class Solution1 {

	public int[][] mergeArrays(int[][] nums1, int[][] nums2) {
		Map<Integer, Integer> map = new HashMap<>();
		for (int[] num : nums1) {
			int id = num[0], val = num[1];
			map.put(id, val);
		}
		for (int[] num : nums2) {
			int id = num[0], val = num[1];
			map.put(id, map.getOrDefault(id, 0) + val);
		}
		int[][] ans = new int[map.size()][2];
		int i = 0;
		for (Map.Entry<Integer, Integer> e : map.entrySet()) {
			ans[i][0] = e.getKey();
			ans[i][1] = e.getValue();
			i++;
		}
		Arrays.sort(ans, (a, b) -> a[0] - b[0]);
		return ans;
	}
}
